package com.example.demo.util;

import lombok.Data;

@Data
public class Result<T> {

    private String code;

    private String message;

    private T data;

    public Result() {
        this.setCode(ResultCode.SUCCESS.getCode());
        this.setMessage(ResultCode.SUCCESS.getMessage());
    }

    public Result(ResultCode code) {
        this.setCode(code.getCode());
        this.setMessage(code.getMessage());
    }

    public Result(T data) {
        this.setCode(ResultCode.SUCCESS.getCode());
        this.setMessage(ResultCode.SUCCESS.getMessage());
        this.setData(data);
    }

    public Result(String code, String message) {
        this.setCode(code);
        this.setMessage(message);
    }

    public static Result success() {
        return new Result();
    }

    public static Result success(Object data) {
        return new Result(data);
    }

    public static Result error() {
        return new Result(ResultCode.ERROR.getCode(), ResultCode.ERROR.getMessage());
    }

    public static Result error(ResultCode resultCode) {
        return new Result(resultCode);
    }

    public static Result error(String message) {
        return new Result(ResultCode.ERROR.getCode(),message);
    }
}
